﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADC.DAL;

namespace ADC.BL
{
    public class FileUploadFactory
    {
        public static List<FileUpload> GetAll()
        {
            var db = new dbADCEntities();
            return db.FileUploads.ToList();
        }

        public static List<FileUpload> GetAllImages()
        {
            var db = new dbADCEntities();
            return db.FileUploads.Where(g => g.IsImage == true).ToList();
        }

        public static FileUpload SelectByID(int ID)
        {
            var db = new dbADCEntities();
            return db.FileUploads.Where(g => g.FileID == ID).FirstOrDefault();
        }

        public static int Update(FileUpload fileUpload)
        {
            var db = new dbADCEntities();
            var objFile = new FileUpload();
            objFile = db.FileUploads.Where(g => g.FileID == fileUpload.FileID).FirstOrDefault();
            objFile.Title = fileUpload.Title;
            objFile.Link = fileUpload.Link;
            objFile.IsImage = fileUpload.IsImage;
            if (fileUpload.FilePath != "")
            {
                objFile.FilePath = fileUpload.FilePath;
            }
            return db.SaveChanges();
        }

        public static int Insert(FileUpload file)
        {
            var db = new dbADCEntities();
            db.AddToFileUploads(file);
            return db.SaveChanges();
        }

        public static int Delete(int fileID)
        {

            var db = new dbADCEntities();
            var file = db.FileUploads.Where(g => g.FileID == fileID).FirstOrDefault();
            db.DeleteObject(file);
            return db.SaveChanges();
        }
    }
}
